<template>
    <div>
        <el-dialog
                title="项目选择"
                :visible.sync="dialogVisible"
                width="80%" :close-on-click-modal="false" :close-on-press-escape="false"
                >
       <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item >
          <el-input v-model="dataForm.code"  clearable  placeholder="编码"></el-input>
        </el-form-item>
        <el-form-item >
          <el-input v-model="dataForm.name" clearable   placeholder="名称"></el-input>
        </el-form-item>
         <el-form-item >
              <el-select v-model="dataForm.projectStatus" clearable  placeholder="请选择项目状态">
                  <el-option
                          v-for="item in projectStatusoptions"
                          :key="item.dictCode"
                          :label="item.dictName"
                          :value="item.dictCode">
                  </el-option>
              </el-select>
          </el-form-item>
           <el-form-item >
               <el-select v-model="dataForm.investmentStatus" clearable  placeholder="请选择投资状态">
                   <el-option
                           v-for="item in investmentStatusoptions"
                           :key="item.dictCode"
                           :label="item.dictName"
                           :value="item.dictCode">
                   </el-option>
               </el-select>
           </el-form-item>
           <el-form-item >
               <el-select v-model="dataForm.qualityStatus" clearable  placeholder="请选择质量整改状态">
                   <el-option
                           v-for="item in qualityStatusoptions"
                           :key="item.dictCode"
                           :label="item.dictName"
                           :value="item.dictCode">
                   </el-option>
               </el-select>
           </el-form-item>
        <el-form-item>
          <el-button type="primary"   @click="getDataList(1)">{{ $t('query') }}</el-button>
        </el-form-item>
        <el-form-item>
               <el-button type="success"   @click="selectHandle()">选择</el-button>
        </el-form-item>
      </el-form>

      <el-table v-loading="dataListLoading" :data="dataList" border @row-dblclick="selectHandle"   @selection-change="dataListSelectionChangeHandle" @sort-change="dataListSortChangeHandle"   style="width: 100%;">
        <el-table-column type="selection" header-align="center" align="center" width="50" ></el-table-column>
        <el-table-column prop="code" label="应用编码" sortable="custom" header-align="center" align="center"></el-table-column>
            <el-table-column prop="name" label="应用名称" sortable="custom" header-align="center" align="center"></el-table-column>
            <el-table-column prop="plannedBuildarea" label="计划建筑面积" sortable="custom" header-align="center" align="center"></el-table-column>
            <el-table-column prop="plannedInvestment" label="计划总投资" sortable="custom" header-align="center" align="center"></el-table-column>
            <el-table-column prop="pstartDate" label="开工日期" sortable="custom" header-align="center" align="center"></el-table-column>
            <el-table-column prop="cumulativeInvestment" label="累计完成投资" sortable="custom" header-align="center" align="center"></el-table-column>
            <el-table-column prop="actualInvestment" label="实际总投资" sortable="custom" header-align="center" align="center"></el-table-column>
          <el-table-column prop="projectProgress" label="项目进度（100%）" sortable="custom" header-align="center" align="center"></el-table-column>
          <el-table-column prop="duration" label="项目实际天数" sortable="custom" header-align="center" align="center"></el-table-column>
          <el-table-column prop="qualitySum" label="质量问题总数" sortable="custom" header-align="center" align="center"></el-table-column>
          <el-table-column prop="qualityProgress" label="质量整改进度（100%）" sortable="custom" header-align="center" align="center"></el-table-column>
          <el-table-column prop="projectStatus" label="工程状态" sortable="custom" header-align="center" align="center">
              <template slot-scope="scope">
                  <el-tag  size="mini" type="danger"><span>{{fomatMethod(scope.row.projectStatus)}}</span></el-tag>
              </template>
          </el-table-column>
          <el-table-column prop="investmentStatus" label="投资状态" sortable="custom" header-align="center" align="center">
              <template slot-scope="scope">
                  <el-tag  size="mini" type="danger"><span>{{fomatMethod1(scope.row.investmentStatus)}}</span></el-tag>
              </template>
          </el-table-column>
          <el-table-column prop="qualityStatus" label="质量整改状态" sortable="custom" header-align="center" align="center">
              <template slot-scope="scope">
                  <el-tag  size="mini" type="danger"><span>{{fomatMethod2(scope.row.qualityStatus)}}</span></el-tag>
              </template>
          </el-table-column>
              <el-table-column prop="status" sortable="custom" label="状态" header-align="center" align="center">
           <template slot-scope="scope">
               <el-tag  size="mini" type="success">{{ scope.row.status | statusFilter }}</el-tag>
           </template>
          </el-table-column>
              <el-table-column prop="createDate" label="创建时间" sortable="custom" header-align="center" align="center"></el-table-column>
              <el-table-column prop="updateDate" label="更新时间" sortable="custom" header-align="center" align="center"></el-table-column>
          <!--  <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="200">
        <template slot-scope="scope">
          <el-button  type="danger" size="mini" @click="selectHandle(scope.row.id,scope.row.code,scope.row.name)">确定</el-button>
        </template>
        </el-table-column>-->
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
        </el-dialog>
    </div>
</template>

<script>
import Bus from '@/api/bus.js'
import mixinViewModule from '@/mixins/view-module'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/basic/bimproject/page',
        getDataListIsPage: true,
        exportURL: '/basic/bimproject/export',
        deleteURL: '/basic/bimproject',
        enableURL: '/basic/bimproject/enable',
        stopURL: '/basic/bimproject/stop',
        deleteIsBatch: true
      },
      dialogVisible: false,
      statusoptions: [{
        value: 1,
        label: '正常'
      }, {
        value: 0,
        label: '停用'
      }],
      dataForm: {
        id: '',
        code: '',
        name: '',
        projectStatus: '',
        status: 1
      },
      getDicListURL: '/sys/dict/type/',
      projectStatusoptions: [],
      projectStatusmaps: '',
      qualityStatusoptions: [],
      qualityStatusmaps: '',
      investmentStatusoptions: [],
      investmentStatusmaps: ''
    }
  },
  activated () {
    this.getProjectStatusInfo()
    this.getQualityStatusInfo()
    this.getInvestmentStatusInfo()
  },
  filters: {
    statusFilter (status) {
      const statusMap = {
        0: '停用',
        1: '正常'
      }
      return statusMap[status]
    }
  },
  methods: {
    init () {
      this.dialogVisible = true
      this.getProjectStatusInfo()
      this.getQualityStatusInfo()
      this.getInvestmentStatusInfo()
      this.getDataList()
    },
    selectHandle (row) {
      if (row) {
        Bus.$emit('val', row.id + ',' + row.code + ',' + row.name)
      } else {
        if (!row && this.dataListSelections.length !== 1) {
          return this.$message({
            message: '请选择且只选择一个操作项',
            type: 'warning',
            duration: 500
          })
        }
        this.dataListSelections.map(item =>
          Bus.$emit('val', item.id + ',' + item.code + ',' + item.name)
        )
      }
      this.dialogVisible = false
    },
    fomatMethod (value) {
      return this.projectStatusmaps[value]
    },
    fomatMethod1 (value) {
      return this.investmentStatusmaps[value]
    },
    fomatMethod2 (value) {
      return this.qualityStatusmaps[value]
    },
    // 获取工程状态信息
    getProjectStatusInfo () {
      this.$http.get(this.getDicListURL + 'projectStatus').then(({ data: res }) => {
        if (res.code !== 0) {
          return false
        }
        this.projectStatusoptions = {
          ...this.projectStatusoptions,
          ...res.data.list
        }
        this.projectStatusmaps = {
          ...this.projectStatusmaps,
          ...res.data.map
        }
      }).catch(() => {})
    },
    // 获取质量状态信息
    getQualityStatusInfo () {
      this.$http.get(this.getDicListURL + 'qualityStatus').then(({ data: res }) => {
        if (res.code !== 0) {
          return false
        }
        this.qualityStatusoptions = {
          ...this.qualityStatusoptions,
          ...res.data.list
        }
        this.qualityStatusmaps = {
          ...this.qualityStatusmaps,
          ...res.data.map
        }
      }).catch(() => {})
    },
    // 获取投资状态信息
    getInvestmentStatusInfo () {
      this.$http.get(this.getDicListURL + 'investmentStatus').then(({ data: res }) => {
        if (res.code !== 0) {
          return false
        }
        this.investmentStatusoptions = {
          ...this.investmentStatusoptions,
          ...res.data.list
        }
        this.investmentStatusmaps = {
          ...this.investmentStatusmaps,
          ...res.data.map
        }
      }).catch(() => {})
    }
  }
}

</script>
